package org.openharmony.qttool.qml.language.editor;

import com.intellij.lang.BracePair;
import com.intellij.lang.PairedBraceMatcher;
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.IElementType;
import org.openharmony.qttool.qml.language.QmlTypes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

class QmlBraceMatcher implements PairedBraceMatcher {

    private static final BracePair[] bracePairs = new BracePair[] {
            new BracePair(QmlTypes.LEFT_BRACE, QmlTypes.RIGHT_BRACE, true),
            new BracePair(QmlTypes.LEFT_BRACKET, QmlTypes.RIGHT_BRACKET, true),
            new BracePair(QmlTypes.LEFT_PAREN, QmlTypes.RIGHT_PAREN, true)
    };

    @Override
    public BracePair @NotNull [] getPairs() {
        return bracePairs;
    }

//    是否允许在单个左括号之后插入成对括号
    @Override
    public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lBraceType,
                                                   @Nullable IElementType contextType) {
        return true;
    }

    @Override
    public int getCodeConstructStart(PsiFile psiFile, int openingBraceOffset) {
        return openingBraceOffset;
    }
}
